﻿@model Amazon.Checkout.ViewModels.CheckoutByAmazonButtonEditPartViewModel

@using System.Web.Mvc;

@{
    Script.Require("JQuery").AtHead();
    var upsellByCategoriesStyle = (string.IsNullOrEmpty(Model.Part.UpsellType) || Model.Part.UpsellType == "ByCategories") ? "" : "display:none";
    var upsellByProductsStyle = Model.Part.UpsellType == "ByProducts" ? "" : "display:none";
}

<fieldset>
    <legend>@T("Amazon Settings")</legend>

    <div>
        @Html.LabelFor(m => m.Part.PromotionId, T("Promotion Code")) 
        @Html.DropDownList("PromotionId", new SelectList(Model.Promotions.ToList().ToDictionary(key => key.Id, value => value.PromotionCode), "Key", "Value", Model.Part.PromotionId))
    </div>

    <div>
        @Html.LabelFor(m => m.Part.TaxId, T("Tax Name")) 
        @Html.DropDownList("TaxId", new SelectList(Model.TaxTables.ToList().ToDictionary(key => key.Id, value => value.Name), "Key", "Value", Model.Part.TaxId))
    </div>

    <h3>@T("Shipping Methods")</h3>
    @if (Model.ShippingMethods != null) {
    <div>
        <ul>
            @foreach (var item in Model.ShippingMethods)
            {
                var included = (Model.Part.ShippingMethods ?? "").Contains(item.Id.ToString());
                var itemChecked = included ? "checked='checked'" : "";
                
                <li style="float:left;display:block;width:200px;">
                    <input type="checkbox" value="@item.Id" name="ShippingMethods" @itemChecked />
                    <label class="forcheckbox" for="InclusionCategories.@item">@item.DisplayableShippingLabel</label>
                </li>
            }
        </ul>
        <div style="clear:left;"></div>
    </div>
    }
    
    <h3>@T("Upselling Items")</h3>
    @Html.RadioButton("UpsellType", "ByCategories", (string.IsNullOrEmpty(Model.Part.UpsellType) || Model.Part.UpsellType == "ByCategories"), new { id = "radio-upsell-by-categories" })<span style="vertical-align:top;">Up-sell by categories</span>
    @Html.RadioButton("UpsellType", "ByProducts", Model.Part.UpsellType == "ByProducts", new { id = "radio-upsell-by-products" }) <span style="vertical-align:top;">Up-sell by products</span>
    
    <div id="upsell-by-products" style="@upsellByProductsStyle">
        @Html.LabelFor(m => m.Part.UpsellingProducts, T("ASINs (comma-separated):")) 
        @Html.TextBox("UpsellingProducts", Model.Part.UpsellingProducts, new { @class = "large text" }) 
    </div>

    <div id="upsell-by-categories" style="@upsellByCategoriesStyle">
        <div>
            <strong>@T("Inclusion Categories")</strong><br/>
            <ul>
            @foreach (var category in Model.Categories)
            {
                var included = (Model.Part.InclusionCategories != null && Model.Part.InclusionCategories.Contains(category));
                var itemChecked = included ? "checked='checked'" : "";
                
                <li style="float:left;display:block;width:200px;">
                    <input type="checkbox" value="@category" name="InclusionCategories.@category" @itemChecked />
                    <label class="forcheckbox" for="InclusionCategories.@category">@category</label>
                </li>
            }
            </ul>
        </div>
   
        <div style="clear:left">
            <strong>@T("Exclusion Categories")</strong><br/>
            <ul>
            @foreach (var category in Model.Categories)
            {
                var included = (Model.Part.ExclusionCategories != null && Model.Part.ExclusionCategories.Contains(category));
                var itemChecked = included ? "checked='checked'" : "";
                
                <li style="float:left;display:block;width:200px;">
                    <input type="checkbox" value="@category" name="ExclusionCategories.@category" @itemChecked />
                    <label class="forcheckbox" for="ExclusionCategories.@category">@category</label>
                </li>
            }
            </ul>
        </div>
    </div>
</fieldset>

<script type="text/javascript">
    $(document).ready(function () {
        $("input[type='radio']").each(function () {
            $(this).change(function () {
                if ($(this).val() == "ByCategories") {
                    $("#upsell-by-products").hide();
                    $("#upsell-by-categories").show();
                }
                else {
                    $("#upsell-by-categories").hide();
                    $("#upsell-by-products").show();
                }
            });
        })
    });
</script>


